<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>标题</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
</head>
<body>
    <div id="root">
        <h2 :style={opacity:opacity}>欢迎学习{{n}}</h2>
        <button @click="opacity=1">透明度设置为正常</button>
        <button @click="stop">点击停止</button>
    </div>
</body>
    <script type="text/javascript">
        Vue.config.productionTip = false

       const vm = new Vue({
            el:'#root',
            data:{  
              opacity:1,
              n:'Vue',
            },
            computed:{
            //计算方法
            
            },
            methods:{
            //方法
                stop(){
                    // 过于温柔，后续可继续修改值
                    // clearInterval(this.timer)
                    this.$destroy()
                }
            },
            filters:{
            //过滤器
            
            },
            mounted(){
            //vue完成模型的解析，将真实dom元素放入页面后，调动mounted,之前为初始化
                this.timer=setInterval(() => {
                    console.log('setInterval')
                            this.opacity -=0.01
                            if (this.opacity<=0)
                            this.opacity=1
                }, 16);
            },
            beforeCreate() {
                console.log('beforeCreate',this)
            },
            created(){
                console.log('created')
            },
            beforeMount(){
                console.log('beforeMount')
            },beforeDestroy() {
                console.log('vm即将驾鹤西游')
                clearInterval(this.timer)
            },
        })
       
        </script>
    </html>
